//
//  YOSessionManager.m
//  Youhuiju
//
//  Created by 余尚飞 on 2016/10/3.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "YOSessionManager.h"

//超时时间
static int const DEFAULT_REQUEST_TIME_OUT = 20;

@implementation YOSessionManager

static  YOSessionManager *shareInstance = nil;

+(YOSessionManager *)shareInstance
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        shareInstance = [[self alloc]init];
    });
    return shareInstance;
}

+(instancetype)allocWithZone:(struct _NSZone *)zone
{
    if (shareInstance == nil)
    {
        shareInstance = [super allocWithZone:zone];
    }
    return shareInstance;
}

-(id)copyWithZone:(NSZone *)zone
{
    return shareInstance;
}

-(instancetype)init
{
    self = [super init];
    if (self)
    {
        //初始化一些必须参数，根据实际情况去设置
        self.responseSerializer = [AFJSONResponseSerializer serializer];
        self.requestSerializer = [AFJSONRequestSerializer serializer];
//        self.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json", @"text/json", nil];
       self.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json", @"text/plain", @"text/html", nil];
        

//        self.responseSerializer.acceptableStatusCodes = [];
        [[self requestSerializer] setTimeoutInterval:DEFAULT_REQUEST_TIME_OUT];
    }
    return self;
}


// @interface AFJSONRequestSerializer : AFHTTPRequestSerializer

//+ (instancetype)serializer {
//    
//    return [self serializerWithWritingOptions:(NSJSONWritingOptions)0];
// }
//
//
// + (instancetype)serializerWithWritingOptions:(NSJSONWritingOptions)writingOptions
//{
//        AFJSONRequestSerializer *serializer = [[self alloc] init];
//         serializer.writingOptions = writingOptions;
//    
//         return serializer;
//     }

@end
